<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>司机管理</title>

<link rel="stylesheet" type="text/css" href="../bootstarp-3.3.7/css/bootstrap.min.css"/>
<script src="../assets/js/jquery-2.0.3.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../bootstarp-3.3.7/js/bootstrap.min.js" type="text/javascript" charset="utf-8"></script>

<link rel="stylesheet" type="text/css" href="../bootstarp-table-1.11.1/bootstrap-table.min.css"/>
<script src="../bootstarp-table-1.11.1/bootstrap-table.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../bootstarp-table-1.11.1/bootstrap-table-zh-CN.min.js" type="text/javascript" charset="utf-8"></script>
  



<script type="text/javascript">
	$(function(){
		$("#tab").bootstrapTable({
			url:"../driver/selectDriver.lgg",
			pagination:true,
			pageSize:5,
			queryParams:queryParams,
			columns:[{
				field:"driver_id",
				title:"司机编号",
				align:"center"
			},{
				field:"name",
				title:"姓名",
				align:"center"
			},{
				field:"sex",
				title:"性别",
				align:"center"
			},{
				field:"age",
				title:"年龄",
				align:"center"
			},{
				field:"driverage",
				title:"驾龄",
				align:"center"
			},{
				field:"status",
				title:"状态",
				align:"center"
			},{
				field:"license",
				title:"驾证编号",
				align:"center"
			},{
				field:"drivertype",
				title:"驾证类型",
				align:"center"
			},{
				field:"to_date",
				title:"领证日期",
				align:"center"
			},{
				field:"contact",
				title:"司机电话",
				align:"center"
			},{
				title:"操作",

				align:"center",
				formatter:function(value,row,index){
					return '<button class="btn btn-danger glyphicon glyphicon-trash" onclick="dele('+row.driver_id+')">  </button> <button class="btn btn-info glyphicon glyphicon-edit"  onclick="selectOne('+row.driver_id+')"></button>'
				}
			}]
		})
		
	
		
	})
	
	function fun(){
		
		if ($("#myModalLabel").html()=="添加司机信息") {
		
			add()
		} else{
			
			up()
		}
	}
	
	function up(){
	
		
			if ($("#drivername").val().trim().length==0||$("#age").val().trim().length==0||$("#carage").val().trim().length==0||$("#license").val().trim().length==0||$("#cartype").val().trim().length==0||$("#to_date").val().trim().length==0||$("#contact").val().trim().length==0) {
				alert("请完善信息")
			}else if($("#contact").val().trim().length!=11){
					alert("手机号必须11位")
			}else if(age<carage){
				alert("驾龄必须小于司机年龄")
				
			}else{
				
				$.ajax({
						type:"post",
						url:"../driver/upDriver.lgg",
						data:$("#addForm").serialize(),
						success:function(data){
								$("#addModal").modal("hide")
								$("#tab").bootstrapTable("refresh")
						}
				});
			}
		
	}
	
	function selectOne(id){
		$("#myModalLabel").html("修改司机信息");
		$("#btn").attr("onclik","up()")
			$.ajax({
						type:"post",
						url:"../driver/selectOne.lgg",
						data:"driver_id="+id,
						success:function(data){
								$("#driver_id").val(id)
								$("#addModal").modal("show");
								$("#driver_id").val(data.driver_id)
								$("#drivername").val(data.name)
								if (data.sex=="男") {
									$("#man").attr("checked","true")
								}else{
									$("#woman").attr("checked","true")
								}
								$("#age").val(data.age);
								$("#carage").val(data.driverage);
								$("#status").val(data.status);
								$("#license").val(data.license);
								$("#cartype").val(data.drivertype);
								$("#to_date").val(data.to_date)
								$("#contact").val(data.contact)
								
						}
			});
		
		
		
	}
	
	function add(){
		var age = $("#age").val();
		var carage = $("#carage").val();
		$("#myModalLabel").html("添加司机信息");
		if ($("#drivername").val().trim().length==0||$("#age").val().trim().length==0||$("#carage").val().trim().length==0||$("#license").val().trim().length==0||$("#cartype").val().trim().length==0||$("#to_date").val().trim().length==0||$("#contact").val().trim().length==0) {
			alert("请完善信息")
		}else if($("#contact").val().trim().length!=11){
				alert("手机号必须11位")
		}else if(age<carage){
			alert("驾龄必须小于司机年龄")
		}	else{
			$.ajax({
				type:"post",
				url:"../driver/selectByLicense.lgg",
				data:"license="+$("#license").val()+"&contact="+$("#contact").val(),
				success:function(data){
					if (data==0) {
							$.ajax({
								type:"post",
								url:"../driver/addOne.lgg",
								data:$("#addForm").serialize(),
								success:function(data){
									$("#addModal").modal("hide");
									$("#tab").bootstrapTable("refresh");
								}
							});
					} else{
						alert("驾证编号或者手机号已经存在")
					}
				}
			});
		
		}
	}
	
	function show(){
		$("#addModal").modal("show");
		$("#myModalLabel").html("添加司机信息")
		$("#addModal").modal("show");
		$("#driver_id").val("")
		$("#drivername").val("")
		$("#man").attr("checked","true")
		$("#age").val("");
		$("#carage").val("");
		$("#status").val("N");
		$("#license").val("");
		$("#cartype").val("");
		$("#to_date").val("2000-01-01")
		$("#contact").val("")
	}
	
	function select(){
		$("#tab").bootstrapTable('refresh');
	}
	
	function queryParams(){
		return{
			'name':$("#name").val(),
			'drivertype':$("#drivertype").val(),
			'to_date':$("#date").val()
		}
	}
	
	function dele(id){
		
			$.ajax({
				type:"post",
				url:"../driver/delDriver.lgg",
				data:"driver_id="+id,
				success:function(data){
					$("#tab").bootstrapTable("refresh");
				}
			});
		
			
	}
	
	
</script>
</head>
<body>
	

	
	
	<div align="center">
		<form class="form-inline">
			<div class="form-group">
					<label for="exampleInputEmail2">查询：</label>
			<input type="text" id="name" class="form-control" placeholder="请输入司机名称或姓氏">
		
		
			<input type="text" id="drivertype" class="form-control" placeholder="请输入驾照类型">
		
		
									<input type="date" class="form-control" id="date"  placeholder="请输入领证日期">		
		
		<button type="button" id="selectBtn" class="btn btn-default btn-md glyphicon glyphicon-search" onclick="select()"></button>
		<button type="button" id="addBtn" class="btn btn-primary btn-md glyphicon glyphicon-plus" onclick="show()"></button>
		</div>
		</form>
		
	</div>
	<br />
	<table id="tab"></table>
	
	

	
	<div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
			<div class="modal-dialog" role="document">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
						<h4 class="modal-title" id="myModalLabel">添加司机信息</h4>
					</div>
					<div class="modal-body">

					<form class="form-horizontal" id="addForm">
						<input type="hidden" id="driver_id" value="" />
					 <div class="form-group">
    						<label for="inputEmail3" class="col-sm-3 control-label">司机姓名：</label>
   								 <div class="col-sm-8">
     								 <input type="text" class="form-control" id="drivername" name="name" placeholder="请输入司机姓名">
    							</div>
  					</div>
  					
  					<div class="form-group">
    						<label for="inputEmail3" class="col-sm-3 control-label">司机性别：</label>
   								 <div class="col-sm-8">
     								<label class="radio-inline">
     									
  										<input type="radio" name="sex" checked="checked" id="man" value="男"> 男
									</label>
									<label class="radio-inline">
  										<input type="radio" name="sex" id="woman" value="女"> 女
									</label>
    							</div>
  					</div>
  					
  					<div class="form-group">
    						<label for="inputEmail3" class="col-sm-3 control-label">年龄：</label>
   								 <div class="col-sm-2">
   								 	
     								
     								 <input type="text" class="form-control" id="age"  name="age" width="50" placeholder="">
    								
    								

   								 </div>
  					</div>
  					
  					
  					<div class="form-group">
    						<label for="inputEmail3" class="col-sm-3 control-label">驾龄：</label>
   								 <div class="col-sm-2">
     								 <input type="text" class="form-control" id="carage" name="driverage" placeholder="">
    							</div>
  					</div>
  					
  					<div class="form-group">
    						<label for="inputEmail3" class="col-sm-3 control-label">状态：</label>
    								
   								 <div class="col-sm-8">
   								 	
     								 <select class="form-control" id="status" name="status">
								
										<option value="Y">任职期</option>
										<option value="N">空闲期</option>
									</select>   
    							</div>
  					</div>
  					
  					<div class="form-group">
    						<label for="inputEmail3" class="col-sm-3 control-label">驾证编号：</label>
   								 <div class="col-sm-8">
     								 <input type="text" class="form-control" id="license" name="license" placeholder="请输入驾证编号">
    							</div>
  					</div>
  					
  					
  					
  					<div class="form-group">
    						<label for="inputEmail3" class="col-sm-3 control-label">驾证类型：</label>
   								 <div class="col-sm-8">
									<input type="text" class="form-control"id="cartype" name="drivertype" placeholder="请输入驾证类型">		
   								 </div>
  					</div>
						
					<div class="form-group">
    						<label for="inputEmail3" class="col-sm-3 control-label">领证日期：</label>
   								 <div class="col-sm-8">
									<input type="date" class="form-control" id="to_date" name="to_date" value="2000-01-01" placeholder="请输入领证日期">		
   								 </div>
  					</div>
  					<div class="form-group">
    						<label for="inputEmail3" class="col-sm-3 control-label">司机电话：</label>
   								 <div class="col-sm-8">
									<input type="text" class="form-control" id="contact" name="contact" placeholder="请输入司机电话号">		
   								 </div>
  					</div>
					</form>
						
					
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-danger glyphicon glyphicon-remove" data-dismiss="modal" onclick="close()"></button>
						<button type="button" class="btn btn-success glyphicon glyphicon-ok" onclick="fun()"></button>
					</div>
				</div>
			</div>
		</div>
		

</body>
</html>